<template>
<div class="icons">
  <swiper :options = "swiperOption">
    <swiper-slide v-for="(items,index) of pages" :key="index">
      <div class="icon" v-for="item of items" :key="item.id">
        <div class="icon-img">
          <img :src="item.imgUrl">
        </div>
        <p class="icon-desc">{{item.desc}}</p>
      </div>
    </swiper-slide>
    <!-- 小点点 -->
    <div class="swiper-pagination"  slot="pagination"></div>
  </swiper>
  </div>
</template>

<script>
    export default {
        props:['iconsRes'],
        name: "HomeIcons",
        data(){
          return {
            swiperOption:{
              pagination: ".swiper-pagination",
              autoplay:false
            },
            iconList: []
          }
        },
      watch:{
          iconsRes(newVal,oldVal){
            this.iconList = newVal;
          }
      },
      computed:{
          pages(){
            const pages = [];
            this.iconList.forEach((item, index)=>{
              const page = Math.floor(index / 8);
              if(!pages[page]){
                pages[page] = []
              }
              pages[page].push(item)

            });
            return pages
          }
      }
    }
</script>

<style lang="stylus" scoped>
  /*~styles是在webpack.base.conf.js的resolve中进行配置的*/
  @import '~assets/styles/varibles'
  @import "~assets/styles/mixins"

  .icons >>> .swiper-pagination-bullet-active
    background rgba(0,175,190,.8)
  .icons >>> .swiper-container
    margin-left: auto;
    margin-right: auto;
    position: relative;
    overflow: hidden;
    z-index: 1;
    padding-bottom: 0.6rem
    box-sizing: border-box
  .icons
    height:0
    width: 100%
    overflow: hidden
    padding-bottom: 59%
    margin-top: 0.1rem;
  .icon
    width 25%
    float: left
    padding-bottom:25%
    overflow hidden
    position: relative
    height 0
  .icon-img
    position absolute
    top:0
    left:0
    right:0
    bottom:0.44rem
    -webkit-box-sizing: border-box
    -moz-box-sizing: border-box
    box-sizing: border-box
    padding 0.07rem
  .icon .icon-img img
    height 100%
    margin 0 auto
    display: block
  .icon p
    position:absolute
    left:0
    right:0
    bottom:0
    height 0.44rem
    line-height:0.44rem
    text-align center
    color: $darkTextColor
    ellipsis()



</style>
